/**
 * <p>富文本框插件</p>
 * xtype = cceafchart
 * 
 * 注：需要xx和xxjs脚本支持
 * 
 * @module Ext-ux-cceaf-control
 * @class cceaf.control.Chart
 * @extends Ext.Component
 * @since 1.0
 */
Ext.define('cceaf.control.HtmlEditor', {
    extend:'Ext.form.field.TextArea',
	alias: 'widget.cceafhtmleditor',
	uploadImageAction:null,
	uploadFlashAction:null,
	editor:null,
	name:null,
	initComponent : function(){
		if(!this.uploadJson || this.uploadJson == ''){
			throw new Error("please config uploadJson");
		}
		if(!this.fileManagerJson || this.fileManagerJson == ''){
			throw new Error("please config fileManagerJson");
		}
		cceaf.control.HtmlEditor.superclass.initComponent.apply(this, arguments);
	},
	/**  渲染编辑器   **/
    onRender: function(ct,position){
    	cceaf.control.HtmlEditor.superclass.onRender.apply(this, arguments);
    	/** 采用KindEditor组件整合到ext中  **/
    	if(!this.editor){
    		this.editor = KindEditor.create(this.inputEl.dom, {
    			allowFileManager : true,
    			resizeType:1,
    			width:'100%',
    			height:this.height||280,
    			uploadJson:this.uploadJson,
    			formatUploadUrl:false,
    			fileManagerJson:this.fileManagerJson,
    			items : [
    			         'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
    			         'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
    			         'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
    			         'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
    			         'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
    			         'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
    			         'flash', 'media', 'insertfile', 'table', 'hr', 'baidumap', 'pagebreak',
    			         'anchor', 'link', 'unlink'
    			         ],
    			         afterCreate : function() {
    			        	 this.sync();
    			         },
    			         afterBlur:function(){
    			        	 this.sync();
    			         }
    		});
    		if(this.value){//初始化数据
    			this.editor.appendHtml(this.value);
    			this.editor.sync();
    		}
    	}
	},
	destroy:function(){	//销毁控件
		if(this.editor){
			this.editor.remove();
		}
		cceaf.control.HtmlEditor.superclass.destroy.apply(this, arguments);
	},
	getValue:function(){//增加获取值，并将值同步到text中
		if(this.editor){
			this.editor.sync();
		}
		cceaf.control.HtmlEditor.superclass.getValue.apply(this, arguments);
	},
	setValue:function(value){//设置值
		var obj = this;
		setTimeout(function(){
			if(obj.editor){
				obj.editor.remove().create();
				if(!value){
					obj.editor.html("");
				}else{
					obj.editor.html(value);
				}
				obj.editor.sync();
			}
		},500);
		cceaf.control.HtmlEditor.superclass.setValue.apply(this, arguments);//内容先清空
	}
});